﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars.Ribbon;
using System.Diagnostics;

namespace MainUI
{
    public partial class OpenControl : RibbonApplicationUserControl
    {
        public OpenControl()
        {
            InitializeComponent();
            mruFileList = new MRUArrayList(this.panelControl2, Properties.Resources.UnPin, Properties.Resources.Pin, Properties.Resources.Code_Central, false, false);
            mruFileList.LabelClicked += mruFileList_LabelClicked;
            mruFolderList = new MRUArrayList(this.panelControl2, Properties.Resources.UnPin, Properties.Resources.Pin, Properties.Resources.Code_Central, false, true);
            MRUFolderList.LabelClicked += MRUFolderList_LabelClicked;
        }

        void MRUFolderList_LabelClicked(object sender, EventArgs e)
        {
            Process.Start("explorer.exe", (string)sender);
            BackstageView.Ribbon.HideApplicationButtonContentControl();
        }

        void mruFileList_LabelClicked(object sender, EventArgs e)
        {
            MainForm frm = (MainForm)BackstageView.Ribbon.FindForm();
            //frm.OpenFile((string)sender);
            BackstageView.Ribbon.HideApplicationButtonContentControl();
        }

        MRUArrayList mruFileList;
        MRUArrayList mruFolderList;

        public MRUArrayList MRUFolderList { get { return mruFolderList; } }
        public MRUArrayList MRUFileList { get { return mruFileList; } }
        private void galleryControlGallery_ItemClick(object sender, DevExpress.XtraBars.Ribbon.GalleryItemClickEventArgs e)
        {
            this.bsvlOpenItem.Text = e.Item.Caption;
            foreach (GalleryItem item in this.galleryControlClient1.Gallery.Groups[0].Items)
            {
                item.Checked = false;
            }
            e.Item.Checked = true;

            string filename = Application.StartupPath + "\\" + MRUArrayList.MRUFileName;
            string folderName = Application.StartupPath + "\\" + MRUArrayList.MRUFolderName;

            switch (e.Item.Caption)
            {
                case "Tệp tin gần nhất":
                    this.panelControl2.Controls.Clear();
                    MRUFileList.Init(filename, Application.StartupPath);
                    break;
                case "Máy tính":
                    this.panelControl2.Controls.Clear();
                    MRUFolderList.Init(folderName, Application.StartupPath);
                    break;
                case "Dropbox":
                    this.panelControl2.Controls.Clear();
                    break;
                default:
                    this.panelControl2.Controls.Clear();
                    MRUFileList.Init(filename, Application.StartupPath);
                    break;
            }
        }
    }
}
